import pandas as pd
from matplotlib.font_manager import FontProperties
import matplotlib.pyplot as plt
plt.rcParams['axes.unicode_minus'] = False
plt.rcParams['axes.formatter.useoffset'] = False
plt.rcParams['font.sans-serif']=['SimHei']
plt.legend(prop=FontProperties(fname='SimHei'))  # 设置图例中文
funclist=['kmeans.kmeans','kmeansplusplus.KMeansPlusPlus','fuzzy.FuzzyKMeans','one.One']
df=[]
for i in range(4):
    df.append(pd.read_excel("./data/" + funclist[i] + ".xlsx"))
# 读取四个表格数据
writename="memory"
# 绘制曲线图
plt.figure(figsize=(10, 6))
plt.plot(df[0]['i'], df[0][writename], label='传统的k-means')
plt.plot(df[1]['i'], df[1][writename], label='k-means++')
plt.plot(df[2]['i'], df[2][writename], label='模糊k-means算法')
plt.plot(df[3]['i'], df[3][writename], label='该算法')

plt.xlabel('迭代次数', fontproperties='SimHei')
plt.ylabel(writename, fontproperties='SimHei')
plt.legend(framealpha=1)
plt.grid(True)
# 保存为SVG文件
plt.savefig(writename+'.jpg',dpi=500)

plt.show()